package com.godme.jvm;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;


// -XX:PermSize -XXMaxPermSize
// -XX:MetaspaceSize -XX:MaxMetaspaceSize
public class MethodArea {

    // 常量池
    public static void StringConstPoolOOM(){
        Set<String> set = new HashSet<>();
        for(int i=0;;){
            set.add(String.valueOf(i++).intern());
        }
    }


    // 类加载信息
    public static void classOOM(){
        while(true){
            Enhancer enhancer = new Enhancer();
            enhancer.setSuperclass(Object.class);
            enhancer.setUseCache(false);
            enhancer.setCallback(new MethodInterceptor() {
                @Override
                public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
                    return  methodProxy.invokeSuper(o, objects);
                }
            });
            enhancer.create();
        }
    }
}
